/*
 * Created by ZhiHui Liu
 */

#ifndef _NGX_HTTP_UPCONF_MODULE_INCLUDE_H_
#define _NGX_HTTP_UPCONF_MODULE_INCLUDE_H_

#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_http.h>


#define ngx_ftruncate(fd, offset)       ftruncate(fd, offset)
#define ngx_lseek(fd, offset, whence)   lseek(fd, offset, whence)

#define NGX_HTTP_UPCONF_DELAY_DELTE (1000 * 75)

#if (NGX_HTTP_UPSTREAM_CHECK)

extern ngx_module_t ngx_http_upstream_check_module;

typedef struct {
    ngx_uint_t                               type;

    ngx_str_t                                name;

    ngx_str_t                                default_send;

    /* HTTP */
    ngx_uint_t                               default_status_alive;

    ngx_event_handler_pt                     send_handler;
    ngx_event_handler_pt                     recv_handler;

    void *init;
    void *parse;
    void *reinit;

    unsigned need_pool;
    unsigned need_keepalive;
} ngx_check_conf_t;

typedef struct {
    ngx_uint_t                               port;
    ngx_uint_t                               fall_count;
    ngx_uint_t                               rise_count;
    ngx_msec_t                               check_interval;
    ngx_msec_t                               check_timeout;
    ngx_uint_t                               check_keepalive_requests;

    ngx_check_conf_t                        *check_type_conf;
    ngx_str_t                                send;

    union {
        ngx_uint_t                           return_code;
        ngx_uint_t                           status_alive;
    } code;

    ngx_array_t                             *fastcgi_params;

    ngx_uint_t                               default_down;
    ngx_uint_t                               unique;
} ngx_http_upstream_check_srv_conf_t;

#endif

#if (NGX_HTTP_UPSTREAM_KEEPALIVE)

extern ngx_module_t ngx_http_upstream_keepalive_module;

typedef struct {
    ngx_uint_t                         max_cached;
    ngx_msec_t                         keepalive_timeout;

    ngx_queue_t                        cache;
    ngx_queue_t                        free;

    ngx_http_upstream_init_pt          original_init_upstream;
    ngx_http_upstream_init_peer_pt     original_init_peer;

} ngx_http_upstream_keepalive_srv_conf_t;

#endif


#endif /* _NGX_HTTP_UPCONF_MODULE_INCLUDE_H_ */
